<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/layui/css/public.css" media="all">
    <script src="/layui/layui.js" charset="utf-8"></script>
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>

<!-- autocomplete属性，它的作用是历史记录的保存，不进行属性设置，默认打开，  false是关闭-->
<body>
    <div class="layui-form layuimini-form">
        <form class="layui-form" action="" lay-filter="roomForm">
            <div class="layui-form-item">
                <label class="layui-form-label required">房间号</label>
                <div class="layui-input-block">
                    <input type="text" name="roomId" lay-verify="required" lay-reqtext="房间号不能为空" placeholder="请输入房间号"
                    autocomplete="true"
                        value="" class="layui-input">
                </div>
            </div>
            <input type="hidden" name="id" value="" class="layui-input"></input>
            <div class="layui-form-item">
                <label class="layui-form-label">楼层</label>
                <div class="layui-input-block">
                    <input type="number" name="floor" lay-verify="required" lay-reqtext="楼层不能为空" placeholder="请输入楼层"
                    autocomplete="true"
                        value="" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-block">
                    <input type="radio" name="status" value="可租" title="可租" checked>
                    <input type="radio" name="status" value="已租" title="已租">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label required">面积</label>
                <div class="layui-input-block">
                    <input type="text" name="size" lay-verify="required" lay-reqtext="房间面积不能为空" placeholder="请输入房间面积" value="" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">类型</label>
                <div class="layui-input-block">
                    <select name="roomType" lay-verify="required">
                        <option value="">请选择房间类型</option>
                        <option value="单人间">单人间</option>
                        <option value="双人间">双人间</option>
                        <option value="三人间">三人间</option>
                        <option value="优质单人间">优质单人间</option>
                        <option value="优质双人间">优质双人间</option>
                        <option value="优质三人间">优质三人间</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">价格</label>
                <div class="layui-input-block">
                    <input type="number" name="roomPrice" placeholder="请输入价格" value="" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="editBtn">确认修改</button>
                    <button type="reset" class="layui-btn layui-btn-normal">重置</button>
                </div>
            </div>
        </form>
    </div>
    <script src="/layui/layui.js" charset="utf-8"></script>
    <script>
        layui.use(['form','element'], function () {
            var form = layui.form,
                layer = layui.layer,
                element = layui.element
                $ = layui.$;
            
            var data = JSON.parse(localStorage.getItem("roomManager"));

            form.val("roomForm",{
                "id":data.id,
                "roomId":data.roomId,
                "floor":data.floor,
                "status":data.status,
                "size":data.size,
                "roomType":data.roomType,
                "roomPrice":data.roomPrice
            });


            //监听提交
            form.on('submit(editBtn)', function (data) {
                // var index = layer.alert(JSON.stringify(data.field), {
                //     title: '最终的提交信息'
                // },
                $.ajax({
                    "url": "http://localhost:8080/room/edit",
                    "data": data.field,
                    "success": function (result) {
                        if (result.code == 200) {
                            layer.msg("修改成功");
                            // 关闭弹出层
                            layer.close(index);

                            var iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(iframeIndex);
                        } else {
                            layer.msg(result.msg);
                        }
                    }
                })


                // 关闭弹出层
                // layer.close(index);

                // var iframeIndex = parent.layer.getFrameIndex(window.name);
                // parent.layer.close(iframeIndex);

                return false;
            });

        });
    </script>
</body>

</html>